<?php

namespace app\api\controller;

use app\common\controller\Api;

use app\admin\model\agency\AgencyInfo;
/**
 * 商户地点接口
 */
class Agency extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    protected $fields=['real_name','id_number','mobile','wechat','province','city','certificate_img'];
    public function create(){

        $params=$this->getParams($this->fields);
        $this->checkParams($params,$this->fields);
        $params['uid']=$this->uid();
        $info=AgencyInfo::get(['city'=>$params['city'],'status'=>1]);
        if(!empty($info)) $this->error('该地区代理已存在');
        $result=AgencyInfo::create($params);
        $this->success($result);
    }

    public function update(){
        $id=$this->request->post('id');
        $params=$this->getParams($this->fields);
        $result=AgencyInfo::update($params,['id'=>$id]);
        $this->success('',$result);
    }

    public function list(){
        $params=$this->request->post();
        $list=(new AgencyInfo())->getList($params);
        $this->success('',$list);
    }

    public function info(){
        $id=$this->request->get('id');
        $result=AgencyInfo::where(['uid'=>$this->uid()])->find();
        $this->success('',$result);

    }
}
